package hoodoos.rule.script.java;

import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;

public class PureJavaClassLoader extends URLClassLoader {

  public PureJavaClassLoader(URL[] urls, ClassLoader parent) {
    super(urls, parent);
  }

  public PureJavaClassLoader(URL[] urls) {
    super(urls);
  }

  public PureJavaClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
    super(urls, parent, factory);
  }

  @Override
  public Class<?> loadClass(String name) throws ClassNotFoundException {
    synchronized (getClassLoadingLock(name)) {
      Class<?> c = findLoadedClass(name);
      if (c == null) {
        try {
          c = findClass(name);
        }
        catch (ClassNotFoundException e) {
          return super.loadClass(name);
        }
      }
      return c;
    }
  }
}
